package b.wm;

import org.apache.flink.api.common.eventtime.SerializableTimestampAssigner;
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import pojo.UserEvent;

public class WaterMarkTest {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        environment.setParallelism(1);
//        水位线计算时间间隔
        environment.getConfig().setAutoWatermarkInterval(100);
        environment.addSource(new CustomSouce())
                .assignTimestampsAndWatermarks(
                        WatermarkStrategy.<UserEvent>forMonotonousTimestamps()
                                .withTimestampAssigner(
                                        new SerializableTimestampAssigner<UserEvent>() {
                                            @Override
                                            public long extractTimestamp(UserEvent element, long recordTimestamp) {
                                                return element.getTimestemp();
                                            }
                                        }
                                )
                )
                .print();
        environment.execute();

    }
}
